package com.chonglie.gallery;

import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;

import com.chonglie.tools.ImageUtils;

public class ImageAdapter extends BaseAdapter {

	private Context context;
	private List<Integer> imageList;
	private List<int[]> imageSizeList;

	public ImageAdapter(Context context) {
		super();
		this.context = context;

		imageList = ImageUtils.getImageList(null);
		imageSizeList = ImageUtils.getImageSizes(context, imageList);

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.widget.Adapter#getCount()
	 */
	public int getCount() {
		return imageList.size();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.widget.Adapter#getItem(int)
	 */
	public Object getItem(int position) {
		return imageList.get(position);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.widget.Adapter#getItemId(int)
	 */
	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		ImageView imageView = new ImageView(context);
		imageView.setImageResource(imageList.get(position));
		imageView.setScaleType(ScaleType.FIT_XY);
		int[] size = imageSizeList.get(position);
		imageView.setLayoutParams(new Gallery.LayoutParams(size[0], size[1]));
		return imageView;
	}

}
